package com.mzj.saas.commons;

import java.io.Serializable;

/**
 * @Author: wangrl
 * @Description: TODO
 * @Date: 21:34 2018/7/26
 * @Version: 1.0
 */
public class ResultBean<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private String msg; // 提示信息
	private String code; // 返回状态码
	private T resultData; // 结果数据

	public ResultBean() {
		super();
	}

	public ResultBean(T resultData) {
		super();
		this.resultData = resultData;
	}

	public ResultBean(Throwable e) {
		super();
		this.msg = e.getMessage();
	}

	public T getResultData() {
		return resultData;
	}

	public void setResultData(T resultData) {
		this.resultData = resultData;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * 10000 --- 成功
	 * 
	 * @param data
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> successfulResult(T data) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
		resultBean.setMsg(StatusCode.SUCCESS_CODE_10000.getErrorMsg());
		resultBean.setResultData(data);
		return resultBean;
	}

	/**
	 * 成功
	 * 
	 * @param msg
	 * @param data
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> successfulResultWithMsg(String msg, T data) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.SUCCESS_CODE_10000.getErrorCode());
		resultBean.setMsg(msg);
		resultBean.setResultData(data);
		return resultBean;
	}

	/**
	 * 10001 --- 失败
	 * 
	 * @param data
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResult(T data) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
		resultBean.setMsg(StatusCode.ERROR_CODE_10001.getErrorMsg());
		resultBean.setResultData(data);
		return resultBean;
	}

	/**
	 * 30001 --- 系统异常，请稍后再试
	 * 
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultOfException() {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_30001.getErrorCode());
		resultBean.setMsg(StatusCode.ERROR_CODE_30001.getErrorMsg());
		return resultBean;
	}

	/**
	 * 失败10001
	 * 
	 * @param msg
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultWithMsg(String msg) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_10001.getErrorCode());
		resultBean.setMsg(msg);
		return resultBean;
	}

	/**
	 * 参数错误10004
	 * 
	 * @param msg
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultOfParamWithMsg(String msg) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_10004.getErrorCode());
		resultBean.setMsg(msg);
		return resultBean;
	}

	/**
	 * 失败
	 * 
	 * @param code
	 * @param msg
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultWithCodeAndMsg(String code, String msg) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(code);
		resultBean.setMsg(msg);
		return resultBean;
	}

	public static <T>  ResultBean<T> failedResultWithStatus(StatusCode statusCode) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(statusCode.getErrorCode());
		resultBean.setMsg(statusCode.getErrorMsg());
		return resultBean;
	}
	
	/**
	 * 40001 --- accessToken失效
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultOfToken() {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_40001.getErrorCode());
		resultBean.setMsg(StatusCode.ERROR_CODE_40001.getErrorMsg());
		return resultBean;
	}
	/**
	 * 50000 --- 用户已实名
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultOfYesRealName(T data) {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_50000.getErrorCode());
		resultBean.setMsg(StatusCode.ERROR_CODE_50000.getErrorMsg());
		resultBean.setResultData(data);
		return resultBean;
	}
	/**
	 * 50001 --- 用户未实名
	 * @return
	 * @author chensenrong
	 */
	public static <T> ResultBean<T> failedResultOfNotRealName() {
		ResultBean<T> resultBean = new ResultBean<>();
		resultBean.setCode(StatusCode.ERROR_CODE_50001.getErrorCode());
		resultBean.setMsg(StatusCode.ERROR_CODE_50001.getErrorMsg());
		return resultBean;
	}

}
